#pragma once

#include "defines.h"
#include "platform/vk/vk_utils.h"
#include "platform/vk/vk_device_context.h"


namespace vkrender
{
    struct MeshVertex
    {
        glm::vec3 position;
        glm::vec3 color;
        glm::vec2 texcoords;

        static std::vector<VkVertexInputBindingDescription> getBindingDescriptions();
        static std::vector<VkVertexInputAttributeDescription> getAttributeDescriptions();

        bool operator==(const MeshVertex& other) const
        {
            return (position == other.position && color == other.color && texcoords == other.texcoords);
        }
    };

    class VulkanModel
    {
    public:
        VulkanModel(const std::shared_ptr<VulkanDeviceContext>& context, const std::string& filepath);
        ~VulkanModel();

        void bind(VkCommandBuffer commandBuffer) const;
        void draw(VkCommandBuffer commandBuffer) const;

    private:
        void createVertexBuffers(
            const std::vector<MeshVertex>& vertices,
            const std::vector<uint32_t>& indices);

        std::shared_ptr<VulkanDeviceContext> context;
        
        VkBuffer vertexBuffer;
        VkDeviceMemory vertexBufferMemory;
        uint32_t vertexCount;
        VkBuffer indexBuffer;
        VkDeviceMemory indexBufferMemory;
        uint32_t indexCount;
    };
}
